package com.wannengbang.cloudleader.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.IncomeListBean;
import com.wannengbang.cloudleader.utils.DateTimeUtil;
import com.wannengbang.cloudleader.utils.NumberFormatUtils;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 合伙人列表
 */
public class ShareIncomeListNewAdapter extends RecyclerView.Adapter<ShareIncomeListNewAdapter.ViewHolder> {

    private List<IncomeListBean.DataBean.ItemListBean> listsBeans;
    private Context context;

    public ShareIncomeListNewAdapter(List<IncomeListBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_share_income_new_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        IncomeListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        holder.tvTime.setText(DateTimeUtil.format7(new Date(Long.parseLong(dataBean.getCreate_time()) * 1000)));
        String money = NumberFormatUtils.formatTwoDecimal(Double.parseDouble(dataBean.getMoney()) / 100);
        holder.tvMoney.setText("+" + money);
        holder.tvRemark.setText("备注：" + dataBean.getRemark());
        //        'share_money'       => 1,  //分润收益
//        'level_money'       => 11, //级差收益
//        'manage_fund'       => 7,  //管理基金
//        'director_bonuses'  => 8,  //董事分红
//
//        'develop_fund'      => 2,  //发展基金
//        'device_enable'     => 3,  //冻结返现(设备激活)
//        'order_bonuses_one' => 4,  //交易奖励(满5000)
//        'order_bonuses_two' => 5,  //交易奖励(满10000)
//        'target_bonuses'    => 6,  //达标奖励
//        'team_reward'    => 10,  //团队长奖励
//        'device_five_reward' => 17,//五台奖励
//        'device_vip_reward' => 18,//vip机具激活奖励
//        'device_vip_reward' => 19,//运营中心奖励
//        'device_vip_reward' => 20,//交易金
//        'device_vip_reward' => 21,//奖励金

        if (dataBean.getRelation_type() == 1) {
            holder.tvRelationType.setText("分润收益(元)");
        } else if (dataBean.getRelation_type() == 2) {
            holder.tvRelationType.setText("发展基金(元)");
        } else if (dataBean.getRelation_type() == 3) {
            holder.tvRelationType.setText("冻结返现(元)");
        } else if (dataBean.getRelation_type() == 4) {
            holder.tvRelationType.setText("交易奖励(元)");
        } else if (dataBean.getRelation_type() == 5) {
            holder.tvRelationType.setText("交易奖励(元)");
        } else if (dataBean.getRelation_type() == 6) {
            holder.tvRelationType.setText("达标奖励(元)");
        } else if (dataBean.getRelation_type() == 7) {
            holder.tvRelationType.setText("管理基金(元)");
        } else if (dataBean.getRelation_type() == 8) {
            holder.tvRelationType.setText("荣誉董事分红(元)");
        } else if (dataBean.getRelation_type() == 11) {
            holder.tvRelationType.setText("级差收益(元)");
        } else if (dataBean.getRelation_type() == 10) {
            holder.tvRelationType.setText("团队长奖励(元)");
        } else if (dataBean.getRelation_type() == 17) {
            holder.tvRelationType.setText("五台奖励(元)");
        } else if (dataBean.getRelation_type() == 18) {
            holder.tvRelationType.setText("Vip机具激活奖励(元)");
        } else if (dataBean.getRelation_type() == 19) {
            holder.tvRelationType.setText("运营中心奖励(元)");
        } else if (dataBean.getRelation_type() == 20) {
            holder.tvRelationType.setText("交易金(元)");
        } else if (dataBean.getRelation_type() == 21) {
            holder.tvRelationType.setText("奖励金(元)");
        }  else if (dataBean.getRelation_type() == 22) {
            holder.tvRelationType.setText("机构提现奖励");
        } else {
            holder.tvRelationType.setText("");
        }
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.tv_relation_type)
        TextView tvRelationType;
        @BindView(R.id.tv_remark)
        TextView tvRemark;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
